import { SpecimenEntity } from "@scmt/api-lis-specimen";
import { useRequest } from "@scmt/common-hooks";
import { useApi } from "@scmt/core-api";

export const useMerge = () => {
  const $api = useApi();

  const { loading, request } = useRequest({
    generateBarcode: async (entites: SpecimenEntity[]) => {
      return $api.lis.specimen.mergeSpecimen(entites);
    },
  });

  const generateBarcode = (entites: SpecimenEntity[]) => {
    return new Promise<SpecimenEntity>((resolve, reject) => {
      request("generateBarcode", {
        params: entites,
        onSuccess: resolve,
        onFail: reject,
      });
    });
  };

  return {
    loading,
    generateBarcode,
  };
};
